package com.ruoyi.web.controller.pdd;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TlPddMall;
import com.ruoyi.system.service.ITlPddMallService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 店铺Controller
 *
 * @author ruoyi
 * @date 2023-11-12
 */
@RestController
@RequestMapping("/system/mall")
public class TlPddMallController extends BaseController
{
    @Autowired
    private ITlPddMallService tlPddMallService;

    /**
     * 查询店铺列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TlPddMall tlPddMall)
    {
        startPage();
        Long userId = getLoginUser().getUserId();
        tlPddMall.setUserId(userId);
        List<TlPddMall> list = tlPddMallService.selectTlPddMallList(tlPddMall);
        return getDataTable(list);
    }

    /**
     * 导出店铺列表
     */
    @Log(title = "店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TlPddMall tlPddMall)
    {
        List<TlPddMall> list = tlPddMallService.selectTlPddMallList(tlPddMall);
        ExcelUtil<TlPddMall> util = new ExcelUtil<TlPddMall>(TlPddMall.class);
        util.exportExcel(response, list, "店铺数据");
    }

    /**
     * 获取店铺详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tlPddMallService.selectTlPddMallById(id));
    }

    /**
     * 新增店铺
     */
    @Log(title = "店铺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TlPddMall tlPddMall)
    {
        return toAjax(tlPddMallService.insertTlPddMall(tlPddMall));
    }

    /**
     * 修改店铺
     */
    @Log(title = "店铺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TlPddMall tlPddMall)
    {
        if(tlPddMall.getYingliyujing() == null)
        {
            tlPddMall.setYingliyujing(new BigDecimal(0));
        }
        if(tlPddMall.getYouhuiquan() == null)
        {
            tlPddMall.setYouhuiquan(new BigDecimal(0));
        }
        return toAjax(tlPddMallService.updateTlPddMall(tlPddMall));
    }

    /**
     * 删除店铺
     */
    @Log(title = "店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tlPddMallService.deleteTlPddMallByIds(ids));
    }
}
